<template>
  <el-table
    v-loading="loading"
    :data="tableData"
    border
    style="width: 100%"
    @selection-change="$emit('selection-change', $event)"
  >
    <!-- 复选列 -->
    <el-table-column type="selection" width="55" align="center" />

    <!-- 常规列 -->
    <el-table-column type="index" label="序号" width="60" align="center"/>
    <el-table-column prop="probeName" label="探针名称" align="center" />
    <el-table-column prop="submitVerifyTime" label="提交时间" width="180" align="center"/>
    <el-table-column prop="verifyTime" label="校对时间" width="180" align="center"/>
    <el-table-column prop="verifyResult" label="校对结果" width="120" align="center"/>

    <!-- 操作列 -->
    <el-table-column label="操作" width="560" align="center">
      <template #default="{ row }">
        <!-- 固定操作按钮 -->
        <el-button
          size="mini"
          type="text"
          icon="el-icon-document"
          @click="$emit('view-draw', row)"
          v-hasPermi="['probe:version:view']"
        >查看图纸</el-button>

        <!-- 动态显示操作按钮 -->
        <template v-if="row.verifyResult === '等待校对'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleRejectVerification(row)"
            v-hasPermi="['probe:version:submit']"
          >批注并退回</el-button>
        </template>
        <template v-if="row.verifyResult === '等待校对'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleSubmitVerification(row)"
            v-hasPermi="['probe:version:update']"
          >提交审定</el-button>
        </template>
        <template v-if="row.verifyResult === '未通过'">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-message"
            @click="$emit('view-comments', row)"
            v-hasPermi="['probe:version:comment']"
          >查看批注</el-button>
        </template>

      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { submitProbeSignatureToApprove } from '@/api/system/probeSignatureProcess'
export default {
  name: 'verifyComponent',
  props: {
    // 表格数据（数组）
    tableData: {
      type: Array,
      required: true,
      default: () => []
    },
    // 加载状态（布尔值）
    loading: {
      type: Boolean,
      default: false
    },
    // 其他数据（任意类型）
    extraConfig: {
      type: Object,
      default: () => ({})
    }
  },
  created() {
    console.log('verifyComponent created');
    console.log('tableData (initial)', this.tableData);
  },
  watch: {
    tableData: {
      immediate: true,
      handler(newVal) {
        console.log('tableData updated', newVal);
      }
    }
  },
  methods:{
    handleSubmitVerification(row) {
      console.log('row clicked:', row);
      console.log('row keys:', Object.keys(row));
      console.log('probeInfoId:', row.probeInfoId);  // 看这里是否是 undefined
      const note = "submitToApprove"
      this.$emit('submit-nextStage', row, note)
    },
    handleRejectVerification(row) {
      console.log('verify')
      console.log('reject-lastStage', row)
      const note = "submitToVerifyReject"
      this.$emit('reject-lastStage',row,note)
    }
  }
};
</script>
